package com.yuexunit.operationman.nbsy.module.nurse.ui;

import android.content.Intent;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.alibaba.fastjson.JSON;

import com.yuexunit.operationman.nbsy.R;
import com.yuexunit.operationman.nbsy.base.BaseKJActivity;
import com.yuexunit.operationman.nbsy.config.AppConfig;
import com.yuexunit.operationman.nbsy.module.nurse.Bean.NurseBean;
import com.yuexunit.operationman.nbsy.module.nurse.NurseContracts;
import com.yuexunit.operationman.nbsy.module.nurse.model.impl.NursingDetailModel;
import com.yuexunit.operationman.nbsy.module.nurse.presenter.INursingDetailPresenter;
import com.yuexunit.operationman.nbsy.module.nurse.presenter.impl.NursingDetailPresenter;
import com.yuexunit.operationman.nbsy.module.nurse.ui.view.INurseDetailView;
import com.yuexunit.operationman.nbsy.util.ProUtil;
import com.yuexunit.operationman.nbsy.widget.LoadingDialog;

import org.kymjs.kjframe.utils.PreferenceHelper;

import java.util.HashMap;
import java.util.Map;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by chenss on 2017/7/10 0010.
 */

public class Act_Nursing extends BaseKJActivity implements INurseDetailView {
    @Bind(R.id.titlebar_tv_title)
    TextView titlebarTvTitle;
    @Bind(R.id.usr_head)
    ImageView usrHead;
    @Bind(R.id.usr_name)
    TextView usrName;
    @Bind(R.id.usr_age)
    TextView usrAge;
    @Bind(R.id.usr_gender)
    TextView usrGender;
    @Bind(R.id.ops_date)
    TextView opsDate;
    @Bind(R.id.doc_name)
    TextView docName;
    @Bind(R.id.preops_diagnosis)
    TextView preopsDiagnosis;
    @Bind(R.id.position)
    TextView position;
    @Bind(R.id.recipe_date)
    TextView recipeDate;
    @Bind(R.id.recipe_id)
    TextView recipeId;
    @Bind(R.id.hisPatientNo)
    TextView hisPatientNo;

    INursingDetailPresenter presenter;

    LoadingDialog loadingDialog;

    @Override
    public void setRootView() {
        setContentView(R.layout.act_nursing);
        ButterKnife.bind(this);
    }

    @Override
    public void initData() {
        super.initData();
        setTitle();
        loadingDialog = new LoadingDialog(this);
        presenter = new NursingDetailPresenter(this, new NursingDetailModel());
    }

    @Override
    public void onResume() {
        super.onResume();
        Map<String, String> params = new HashMap<>();
        params.put("operationNo", PreferenceHelper.readString(aty, AppConfig.PATIENT_INFO, AppConfig.PATIENT_OPERATION_ID) + "");
        presenter.getNurseDate(params);
    }

    private void setTitle() {
        titlebarTvTitle.setText("手术护理记录单");
    }

    @OnClick({R.id.titlebar_img_back, R.id.ops_adress, R.id.ops_pre, R.id.ops_ing,
            R.id.ops_end, R.id.other, R.id.preview, R.id.ops_sign})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.titlebar_img_back:
                finish();
                break;
            case R.id.ops_adress:
                startActivity(new Intent(aty, Act_Ops_Adress.class));
                break;
            case R.id.ops_pre:
                startActivity(new Intent(aty, Act_Ops_Pre.class));
                break;
            case R.id.ops_ing:
                startActivity(new Intent(aty, Act_Ops_Ing.class));
                break;
            case R.id.ops_end:
                startActivity(new Intent(aty, Act_Ops_End.class));
                break;
            case R.id.other:
//                startActivity(new Intent(aty, Act_Ops_Other.class));
                break;
            case R.id.preview:
                startActivity(new Intent(aty, Act_Ops_Preview.class));
                break;
            case R.id.ops_sign:
                startActivity(new Intent(aty, Act_Ops_Sign.class));
                break;
        }
    }

    @Override
    public void getNurseDate(NurseBean nurseBean) {
        if (AppConfig.isEye && null == nurseBean.getObject().getNursing().getNursingId()) {
            String safe = ProUtil.getJson("Nursing.json",aty);
            NurseBean nurseBean1= JSON.parseObject(safe,NurseBean.class);
            if (nurseBean.getCode() == 200) {
                nurseBean1.getObject().setNursing(nurseBean.getObject().getNursing());
                AppConfig.NURSEBEAN = nurseBean1;

                usrName.setText(AppConfig.NURSEBEAN.getObject().getNursing().getPatientName());
                usrAge.setText(AppConfig.NURSEBEAN.getObject().getNursing().getPatientAge() + "");
                if (AppConfig.NURSEBEAN.getObject().getNursing().getPatientSex().equals("1")) {
                    usrGender.setText("男");
                } else if (AppConfig.NURSEBEAN.getObject().getNursing().getPatientSex().equals("2")) {
                    usrGender.setText("女");
                } else {
                    usrGender.setText("不详");
                }
                opsDate.setText(AppConfig.NURSEBEAN.getObject().getNursing().getOperationDate());
                docName.setText(AppConfig.NURSEBEAN.getObject().getNursing().getDoctorName());
                preopsDiagnosis.setText(AppConfig.NURSEBEAN.getObject().getNursing().getPreoperativeDiagnosis());
                position.setText(AppConfig.NURSEBEAN.getObject().getNursing().getPatientArea());
                recipeDate.setText(AppConfig.NURSEBEAN.getObject().getNursing().getOperationName());
                recipeId.setText(AppConfig.NURSEBEAN.getObject().getNursing().getPatientBed());
                hisPatientNo.setText(AppConfig.NURSEBEAN.getObject().getNursing().getInHospitalNo());
                if (AppConfig.NURSEBEAN.getObject().getNursingItemList() == null) {
                    AppConfig.NURSEBEAN.getObject().setNursingItemList(NurseContracts.nursingItemListEntities_new(this));
                }

//            if(AppConfig.NURSEBEAN.getObject().getAnaesthesia() == null)
//            {
//                AppConfig.NURSEBEAN.getObject().setAnaesthesia(NurseContracts.anaesthesisaEntity(this));
//            }
            }
        } else {
            if (nurseBean.getCode() == 200) {
                AppConfig.NURSEBEAN = nurseBean;
                usrName.setText(AppConfig.NURSEBEAN.getObject().getNursing().getPatientName());
                usrAge.setText(AppConfig.NURSEBEAN.getObject().getNursing().getPatientAge() + "");
                if (AppConfig.NURSEBEAN.getObject().getNursing().getPatientSex().equals("1")) {
                    usrGender.setText("男");
                } else if (AppConfig.NURSEBEAN.getObject().getNursing().getPatientSex().equals("2")) {
                    usrGender.setText("女");
                } else {
                    usrGender.setText("不详");
                }
                opsDate.setText(AppConfig.NURSEBEAN.getObject().getNursing().getOperationDate());
                docName.setText(AppConfig.NURSEBEAN.getObject().getNursing().getDoctorName());
                preopsDiagnosis.setText(AppConfig.NURSEBEAN.getObject().getNursing().getPreoperativeDiagnosis());
                position.setText(AppConfig.NURSEBEAN.getObject().getNursing().getPatientArea());
                recipeDate.setText(AppConfig.NURSEBEAN.getObject().getNursing().getOperationName());
                recipeId.setText(AppConfig.NURSEBEAN.getObject().getNursing().getPatientBed());
                hisPatientNo.setText(AppConfig.NURSEBEAN.getObject().getNursing().getInHospitalNo());
                if (AppConfig.NURSEBEAN.getObject().getNursingItemList() == null) {
                    AppConfig.NURSEBEAN.getObject().setNursingItemList(NurseContracts.nursingItemListEntities_new(this));
                }

//            if(AppConfig.NURSEBEAN.getObject().getAnaesthesia() == null)
//            {
//                AppConfig.NURSEBEAN.getObject().setAnaesthesia(NurseContracts.anaesthesisaEntity(this));
//            }
            }
        }
    }

    @Override
    public void loadingDialogStatus(int status) {
        switch (status) {
            case AppConfig.SHOW_DIALOG:
                loadingDialog.setCanceledOnTouchOutside(false);
                loadingDialog.show();
                break;
            case AppConfig.DISMISS_DIALOG:
                loadingDialog.dismiss();
                break;

        }
    }
}
